package {
	import suites.integration.IntegrationSuite;

	import org.flexunit.internals.TraceListener;
	import org.flexunit.listeners.CIListener;
	import org.flexunit.runner.FlexUnitCore;
	import org.splink.library.loading.QUrlLoader;
	import org.splink.library.queue.QEvent;

	import flash.display.Sprite;
	import flash.net.URLRequest;

	[SWF(backgroundColor="#FFFFFF", frameRate="31", width="640", height="480")]

	public class TestRunner extends Sprite {
		private var core : FlexUnitCore;

		public function TestRunner() {
			var loader : QUrlLoader = new QUrlLoader(new URLRequest("port"));
			loader.register(QEvent.COMPLETE, function(e : QEvent):void {
				start(loader.getContent());
			});
			loader.register(QEvent.ERROR, function(e : QEvent):void {
				start();
			});
			loader.start();
		}

		private function start(port : uint = 1024) : void {
			core = new FlexUnitCore();
			core.addListener(new TraceListener());
			core.addListener(new CIListener(port));
			trace("run suites!");
			core.run(IntegrationSuite);
		}
	}
}
